home *** CD-ROM | disk | FTP | other *** search
/ Gigarom 1 / Gigarom Macintosh Archives (Quantum Leap)(CDRM1080320)(1993).iso / FILES / CDE / D-H / Default CDEF 2.2.cpt / Default CDEF 2.2 / DefaultItem.c < prev    next >
Text File  |  1991-04-10  |  2KB  |  103 lines

  1. /*
  2.     DefaultItem is a dialog user item procedure written using THINK C.  This is a simple
  3.     example of how to draw a default button outline with a user item.  For best results,
  4.     the user item should be disabled and it's display rectangle should surround the
  5.     default button.  The following code shows how the user item would typically be
  6.     initialized.
  7.     
  8.     theDialog = GetNewDialog(DLOG_ID, NIL, -1);
  9.     ...
  10.     GetDItem(theDialog, USER_ITEM_NUM, &itemType, &itemHandle, &itemBox);
  11.     SetDItem(theDialog, USER_ITEM_NUM, itemType, DefaultItem, &itemBox);
  12.     ...
  13.     ShowWindow(theDialog);
  14.     
  15.     © Lim Unlimited, 4 Mar 1991 - All Rights Reserved
  16. */
  17.  
  18.  
  19.  
  20. /*
  21.     header files
  22. */
  23.  
  24. #include <Color.h>
  25. #include <ColorToolbox.h>
  26.  
  27.  
  28.  
  29. /*
  30.     constants and macros
  31. */
  32.  
  33. #define NIL        ((void *) 0)
  34.  
  35. #define INACTIVE    255
  36.  
  37. #define SYS_ENVIRONS_VERSION    1
  38.  
  39. #define OUTLINE_THICKNESS    3
  40. #define OUTLINE_INSET        (OUTLINE_THICKNESS + 1)
  41. #define OUTLINE_OUTSET        (-OUTLINE_INSET)
  42. #define CURVE_ADJUSTMENT    2
  43.  
  44.  
  45.  
  46. /*
  47.     routines
  48. */
  49.  
  50. pascal void        DefaultItem        (DialogPeek, short);
  51.  
  52.  
  53.  
  54. /*
  55.     DefaultItem draws an outline for the default button.  The outline is drawn correctly
  56.     for buttons of any size, color, and state.
  57. */
  58.  
  59. pascal void DefaultItem(theDialog, itemNum)
  60.  
  61. DialogPeek    theDialog;
  62. short            itemNum;
  63.  
  64. {
  65.     short                itemType;
  66.     ControlHandle    theControl;
  67.     Rect                itemBox;
  68.     SysEnvRec        sysEnvirons;
  69.     AuxCtlHndl        auxCtlHdl;
  70.     RGBColor            oldColor, frameColor;
  71.     PenState            penState;
  72.     short                curvature;
  73.     
  74.     GetDItem(theDialog, theDialog->aDefItem, &itemType, &theControl, &itemBox);
  75.     
  76.     if (itemType == (ctrlItem | btnCtrl) && (*theControl)->contrlVis) {
  77.         (void) SysEnvirons(SYS_ENVIRONS_VERSION, &sysEnvirons);
  78.         if (sysEnvirons.hasColorQD) {
  79.             (void) GetAuxCtl(theControl, &auxCtlHdl);
  80.             GetForeColor(&oldColor);
  81.             if (auxCtlHdl) {
  82.                 frameColor = (*(*auxCtlHdl)->acCTable)->ctTable[cFrameColor].rgb;
  83.                 RGBForeColor(&frameColor);
  84.             }
  85.         }
  86.         
  87.         GetPenState(&penState);
  88.         PenNormal();
  89.         PenSize(OUTLINE_THICKNESS, OUTLINE_THICKNESS);
  90.         if ((*theControl)->contrlHilite == INACTIVE) {
  91.             PenPat(&gray);
  92.         }
  93.         InsetRect(&itemBox, OUTLINE_OUTSET, OUTLINE_OUTSET);
  94.         curvature = ((itemBox.bottom - itemBox.top) >> 1) + CURVE_ADJUSTMENT;
  95.         FrameRoundRect(&itemBox, curvature, curvature);
  96.         SetPenState(&penState);
  97.         
  98.         if (sysEnvirons.hasColorQD) {
  99.             RGBForeColor(&oldColor);
  100.         }
  101.     }
  102. }
  103.